package com.isunland.managesystem.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.isunland.managesystem.R;
import com.isunland.managesystem.entity.CurrentUser;
import com.isunland.managesystem.entity.ReplyOtherListBean;
import java.util.List;

/**
 * 对象功能:
 * 开发公司: 北京信普达系统工程有限公司
 * 开发人员: HuXiaoDan
 * 创建时间: 2017/5/2 11:07
 */

@SuppressWarnings("deprecation") public class MyPlanProgressReplyListAdapter
    extends ArrayAdapter<ReplyOtherListBean> {

  private Context mcontext;

  /**
   * ViewHolder class for layout.<br />
   * <br />
   * Auto-created on 2017-05-02 13:46:20 by Android Layout Finder
   * (http://www.buzzingandroid.com/tools/android-layout-finder)
   */
  private static class ViewHolder {
    public final RelativeLayout rootView;
    final RelativeLayout rlOtherReply;
    final RelativeLayout rlMyReply;
    final TextView tvReplyDate;
    final TextView tvOtherReply;
    final TextView tvMyDate;
    final TextView tvMyReply;
    final TextView tvMe;
    final TextView tvOther;

    private ViewHolder(RelativeLayout rootView, RelativeLayout rlOtherReply,
        RelativeLayout rlMyReply, TextView tvReplyDate, TextView tvOtherReply, TextView tvMydate,
        TextView tvMyReply, TextView tvMe, TextView tvOther) {
      this.rootView = rootView;
      this.rlOtherReply = rlOtherReply;
      this.rlMyReply = rlMyReply;
      this.tvReplyDate = tvReplyDate;
      this.tvOtherReply = tvOtherReply;
      this.tvMyDate = tvMydate;
      this.tvMyReply = tvMyReply;
      this.tvMe = tvMe;
      this.tvOther = tvOther;
    }

    public static ViewHolder create(RelativeLayout rootView) {
      RelativeLayout rlOtherReply = (RelativeLayout) rootView.findViewById(R.id.rl_otherReply);
      RelativeLayout rlMyReply = (RelativeLayout) rootView.findViewById(R.id.rl_myReply);
      TextView tvReplyDate = (TextView) rootView.findViewById(R.id.tv_replyDate);
      TextView tvOtherReply = (TextView) rootView.findViewById(R.id.tv_otherReply);
      TextView tvMyDate = (TextView) rootView.findViewById(R.id.tv_myDate);
      TextView tvMyReply = (TextView) rootView.findViewById(R.id.tv_myReply);
      TextView tvMe = (TextView) rootView.findViewById(R.id.tv_me);
      TextView tvOther = (TextView) rootView.findViewById(R.id.tv_reply_name);
      return new ViewHolder(rootView, rlOtherReply, rlMyReply, tvReplyDate, tvOtherReply, tvMyDate,
          tvMyReply, tvMe, tvOther);
    }
  }

  @NonNull @Override
  public View getView(int position, View convertView, @NonNull ViewGroup parent) {
    final ViewHolder vh;
    if (convertView == null) {
      View view = mInflater.inflate(R.layout.item_plan_reply, parent, false);
      vh = ViewHolder.create((RelativeLayout) view);
      view.setTag(vh);
    } else {
      vh = (ViewHolder) convertView.getTag();
    }

    ReplyOtherListBean item = getItem(position);
    if (item == null) {
      return vh.rootView;
    }
    CurrentUser user = CurrentUser.newInstance(mcontext);
    //changeBg(vh.tvOtherReply, "#d4f3f3");
    //changeBg(vh.tvMyReply, "#ffffff");

    if (item.getRegStaffId().equalsIgnoreCase(user.getJobNumber())) {
      //自己的回复
      vh.rlOtherReply.setVisibility(View.GONE);
      vh.rlMyReply.setVisibility(View.VISIBLE);
      vh.tvMyDate.setText(item.getRegDate());
      vh.tvMe.setText("我");
      vh.tvMyReply.setText(item.getReplyMsg());
    } else {
      //其他人的回复
      vh.rlOtherReply.setVisibility(View.VISIBLE);
      vh.rlMyReply.setVisibility(View.GONE);
      vh.tvReplyDate.setText(item.getRegDate());
      vh.tvOther.setText(item.getRegStaffName());
      vh.tvOtherReply.setText(item.getReplyMsg());
    }
    return vh.rootView;
  }

  //private void changeBg(TextView tv, String color) {
  //  int strokeWidth = 1; // 3dp 边框宽度
  //  int roundRadius = 8; // 8dp 圆角半径
  //  //int strokeColor = Color.parseColor("#ffffff");//边框颜色
  //  int fillColor = Color.parseColor(color);//内部填充颜色
  //  GradientDrawable gd = new GradientDrawable();//创建drawable
  //  gd.setColor(fillColor);
  //  gd.setCornerRadius(roundRadius);
  //  gd.setStroke(strokeWidth, getContext().getResources().getColor(R.color.white));
  //  tv.setBackgroundDrawable(gd);
  //}

  private LayoutInflater mInflater;

  // Constructors
  public MyPlanProgressReplyListAdapter(Context context, List<ReplyOtherListBean> objects) {
    super(context, 0, objects);
    this.mInflater = LayoutInflater.from(context);
    this.mcontext = context;
  }
}